package br.roove.bomotivo.ui;

import java.util.ArrayList;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.FragmentManager;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.pm.ActivityInfo;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTransaction;
import android.view.Display;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.GridView;
import android.widget.TextView;
import android.widget.Toast;

public class Galeria extends Fragment implements OnItemClickListener {
	
	int id;
	String BASE_URL = "http://bomotivo.roove.com.br/service/imagens/";
	GridView grid;
	TextView tabText;
	SharedPreferences prefs;
	SharedPreferences.Editor prefs2;
	CustomPhotoAdapter adapter;
	ArrayList<String> imagesToLoad;
	String evento = "";

	public Galeria(ArrayList<String> imagesToLoad, String evento) {
		super();
		this.imagesToLoad = imagesToLoad;
		this.evento = evento;
	}

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		prefs = this.getActivity().getSharedPreferences("eventospref", 0);
		prefs2 = this.getActivity().getSharedPreferences("eventospref", 0).edit();
		
		prefs2.putString("nome2", prefs.getString("nome1", "")).commit();
		prefs2.putString("nome1", "GALERIA - " + getArguments().getString("nome")).commit();
		prefs2.putString("eventotab", getArguments().getString("nome")).commit();
		
		View view = inflater.inflate(R.layout.galeria, container, false);
		tabText = (TextView)getActivity().findViewById(R.id.textViewTab);
		tabText.setText("GALERIA - " + getArguments().getString("nome"));
		grid = (GridView)view.findViewById(R.id.galeria);
		adapter = new CustomPhotoAdapter(getActivity(), imagesToLoad);
		grid.setOnItemClickListener(this);
		grid.setAdapter(adapter);
		return view;
	}

	@Override
	public void onActivityCreated(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onActivityCreated(savedInstanceState);
		

	}

	@Override
	public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
		// TODO Auto-generated method stub
		grid.setFocusable(false);
		FotoAumentada fotoaumentada = new FotoAumentada(imagesToLoad.get(arg2));
		FragmentTransaction ft = getFragmentManager().beginTransaction().add(R.id.fragment_main, fotoaumentada).addToBackStack("Foto");
		ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN).commit();
		
		
	}
	
	
	
//	public void changeFragment(String URL){
//		FotoAumentada fotoaumentada = new FotoAumentada(URL);
//		FragmentTransaction ft = getFragmentManager().beginTransaction().add(R.id.fragment_main, fotoaumentada);
//		ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN).commit();
//	}
	
	
	

}
